<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
        components: {
            SelectImage: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectImage())
        },
        data() {
            return {
                appWindow: window,
                form: {
                    bonusSet: {
                        status: 1,
                        ratio_module: 0,
                    },

                },
                loading: true,

                editVisible: false,

                levelValue1: "",
                levelValue2: "",

                visible: false,
            };
        },
        methods: {
            // 批量操作
            batch() {
                this.form.bonusSet.independent_set.forEach(element => {
                    element.bonus.forEach(item => {
                        item.ratio = this.levelValue1;
                        item.money = this.levelValue2;
                    });
                });
                this.visible = false;
            },
            async getData() {
                let res = await this.$vFN.Http.post({
                    url: "plugin/team-dividend/admin/product/detail",
                    data: {
                        product_id: this.id,
                    }
                },window);
                this.form = res.data;
            },
            async sum() {
                let res = await this.$vFN.Http.post({
                    url: "plugin/team-dividend/admin/product/setParticipate",
                    data: {
                        product_id: this.id,
                        status: this.form.bonusSet.status,
                        ratio_module: this.form.bonusSet.ratio_module,
                        independent_set: this.form.bonusSet.independent_set,
                        default: this.form.bonusSet.default
                    }
                }, window);
                if(res.code == 200) {
                    this.$vFN.Tools.messageSuccess("操作成功");
                    this.onSuccess();
                    this.editVisible = false;
                }
            },
            // 初始化
            async init() {
                this.editVisible = true;
                this.loading = false;
                this.getData();
                // this.form.albumUrl = this.data.albumUrl;
                // this.form.name = this.data.name;
                // this.form.salePrice = this.data.salePrice;
                // this.form.orderSales = this.data.orderSales;
                
                // if(this.data.bonus_status == 0) {
                //     this.form.status = 1;
                // }else {
                //     this.form.status = 0;
                // }
            },
            onSuccess() {},

            excel() {
                this.editVisible = false;
            },

        },
        mounted() {
            this.init();
        },
        activated() {},
    };
</script>